package networkSimulation.framework

import collection.mutable.Publisher
import java.lang.reflect.Method

/**
 * Custom Observable class, which extends the built-in Publisher of Scala
 *
 * @author  Tim Caljé
 *          Jeroen De Raedt
 *          Jorick Van Aken
 */
class Observable extends Publisher[Method] {
  // this class is added to automatically add the publishing method to the publish() method of the Publisher

  /**
   * Publish an event to the listeners of this object.
   * It will provide the calling object and method to the listeners
   */
  def publish() {
    // since there doesn't appear to be a function to retrieve the current method in Scala, this hack was implemented:
    // We throw a RuntimException, and from its stacktrace we retrieve the the name of the method
    var methodName = new RuntimeException().getStackTrace.apply(1).toString.split('(').head.split('.').last
    super.publish(this.getClass().getMethods.find(_.getName() == methodName).get)
  }

}